home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-25 | 8.3 KB | 275 lines | [TEXT/PJMM] |
- { Tools Plus Tutorial - - Buttons on two windows }
-
- { NOTE: }
- { The MWERKS compiler directived ($IFC MWERKS) indicates code that is compiled only by }
- { the CodeWarrior compiler. THINK Pascal and Metrowerks CodeWarrior Pascal have }
- { _slight_ differences, and this compiler directive lets you use one source for both compilers. }
- { You can remove the code that does not pertain to your compiler. }
-
-
- program Tutorial;
- uses
- {$IFC MWERKS}
- Dialogs, Fonts, Processes, SegLoad, TextEdit, ToolsPlus, Windows;
- {$ELSEC}
- ToolsPlus;
- {$ENDC}
-
-
- const
- { Menu constants to make code more readable…}
- ApplMenu = 0;
- FileMenu = 1;
- EditMenu = 2;
-
- { Window constants (just to make the code readable)… }
- VendorWindow = 1;
- DebuggerWindow = 2;
-
- { Button constants… }
- OkButton = 255;
- CancelButton = 254;
-
- checkSymFile = 1;
- checkFullPath = 2;
- checkLinkMap = 3;
- checkA6 = 4;
- checkDebugger = 5;
-
- typeAle = 1;
- typeDraft = 2;
- typeLager = 3;
- typeLite = 4;
- typeWater = 5;
- levelHigh = 10;
- levelMedium = 11;
- levelLow = 12;
-
-
- var
- Poll: TPPollRecord; {Polling record to retrieve event information}
- ExitTheDemo: boolean; {Should the demo terminate?}
- theButton: integer; {Button counter }
-
-
-
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - }
- procedure ProcessMenuSelection;
- const
- NewItem = 1;
- OpenItem = 2;
- CloseItem = 3;
- QuitItem = 5;
- var
- theButton: integer;
- begin
-
- case Poll.Menu.Num of
- ApplMenu: {Apple menu's 'About…' item}
- theButton := AlertBox(NoIcon, 'This is my application’s about box. (Click to close)', NoButtonAlert);
-
- FileMenu:
- case Poll.Menu.Item of
- NewItem:
- ;
- OpenItem:
- ;
- CloseItem:
- ;
- QuitItem:
- ExitTheDemo := true;
- end
- end;
-
- MenuHilite(0); {Turn off highlighted menu}
- end;
-
-
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - }
- procedure DrawVendorWindow;
- var
- theRect: rect;
- theStr: Str255;
- begin
- { Draw the contents of a window. It's good to have this code in a separate routine because you }
- { need to use it [1] when a window is first opened, and [2] when a window needs to be refreshed. }
-
- CurrentWindow(VendorWindow); {Subsequent drawing takes place on this window (current grafPort) }
- TextFont(systemFont);
- TextSize(12);
-
- { Draw the 'Type' group box… }
- SetRect(theRect, 15, 18, 85, 112);
- FrameRect(theRect);
- SetRect(theRect, 20, 10, 56, 26);
- theStr := 'Type';
- {$IFC MWERKS}
- TETextBox(ptr(ord(@theStr) + 1), length(theStr), theRect, teJustCenter);
- {$ELSEC}
- TextBox(ptr(ord(@theStr) + 1), length(theStr), theRect, teJustCenter);
- {$ENDC}
-
- { Draw the 'Level' group box… }
- SetRect(theRect, 130, 18, 220, 85);
- FrameRect(theRect);
- SetRect(theRect, 135, 10, 177, 26);
- theStr := 'Level';
- {$IFC MWERKS}
- TETextBox(ptr(ord(@theStr) + 1), length(theStr), theRect, teJustCenter);
- {$ELSEC}
- TextBox(ptr(ord(@theStr) + 1), length(theStr), theRect, teJustCenter);
- {$ENDC}
- end;
-
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - }
- procedure ApplicationInitialization;
- begin
- { Do all the application setup before you start polling for events… }
-
- { Create an Apple menu with an 'About…' item…}
- AppleMenu('About My App…');
-
- { Create the standard File and Edit menus…}
- Menu(FileMenu, 0, enabled, 'File');
- Menu(FileMenu, 1, disabled, 'New/N');
- Menu(FileMenu, 2, disabled, 'Open/O');
- Menu(FileMenu, 3, disabled, 'Close/W');
- Menu(FileMenu, 4, disabled, mDividingLine);
- Menu(FileMenu, 5, enabled, 'Quit/Q');
-
- Menu(EditMenu, 0, enabled, 'Edit');
- Menu(EditMenu, 1, disabled, 'Undo/Z');
- Menu(EditMenu, 2, disabled, mDividingLine);
- Menu(EditMenu, 3, disabled, 'Cut/X');
- Menu(EditMenu, 4, disabled, 'Copy/C');
- Menu(EditMenu, 5, disabled, 'Paste/V');
- Menu(EditMenu, 6, disabled, 'Clear');
- Menu(EditMenu, 7, disabled, mDividingLine);
- Menu(EditMenu, 8, disabled, 'Show Clipboard…');
- UpdateMenuBar;
-
-
- { Create the 'Vendor' window and populate it…}
- WindowOpen(VendorWindow, 0, 0, 250, 150, 'Vendor', noGrowDocProc + wTile, GoAway, NotModal);
- TextFont(geneva);
- TextSize(9);
- NewButton(typeAle, 25, 30, 60, 42, 'Ale', radioButProc + useWFont, enabled, selected);
- NewButton(typeDraft, 25, 45, 70, 57, 'Draft', radioButProc + useWFont, enabled, notSelected);
- NewButton(typeLager, 25, 60, 70, 72, 'Lager', radioButProc + useWFont, enabled, notSelected);
- NewButton(typeLite, 25, 75, 62, 87, 'Lite', radioButProc + useWFont, enabled, notSelected);
- NewButton(typeWater, 25, 90, 70, 102, 'Water', radioButProc + useWFont, enabled, notSelected);
-
- NewButton(levelHigh, 140, 29, 190, 43, 'High', radioButProc, enabled, notSelected);
- NewButton(levelMedium, 140, 46, 214, 60, 'Medium', radioButProc, enabled, selected);
- NewButton(levelLow, 140, 63, 188, 77, 'Low', radioButProc, enabled, notSelected);
-
- NewButton(CancelButton, 110, 110, 167, 130, 'Cancel', pushButProc, enabled, notSelected);
- NewButton(OkButton, 185, 110, 235, 130, 'Ok', pushButProc + DefaultButton, enabled, notSelected);
- DrawVendorWindow;
-
-
- { Create the 'Debugger' window and populate it… }
- WindowOpen(DebuggerWindow, 0, 0, 250, 150, 'Debugger', noGrowDocProc + wTile, GoAway, NotModal);
- NewButton(checkSymFile, 35, 10, 160, 26, 'Create SYM File', checkBoxProc, enabled, notSelected);
- NewButton(checkFullPath, 53, 26, 208, 42, 'Full Path in SYM File', checkBoxProc, disabled, notSelected);
- NewButton(checkLinkMap, 35, 42, 180, 58, 'Generate Link Map', checkBoxProc, enabled, notSelected);
- NewButton(checkA6, 35, 58, 230, 74, 'Generate A6 Stack Frames', checkBoxProc, enabled, notSelected);
- NewButton(checkDebugger, 35, 74, 200, 90, 'The Debugger™ Aware', checkBoxProc, enabled, notSelected);
-
- NewButton(CancelButton, 110, 110, 167, 130, 'Cancel', pushButProc, enabled, notSelected);
- NewButton(OkButton, 185, 110, 235, 130, 'Ok', pushButProc + DefaultButton, enabled, notSelected);
-
-
- ExitTheDemo := false;
- end;
-
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - }
- begin
- {$IFC MWERKS}
- {Toolbox initialization - - Done automatically by THINK Pascal}
- InitGraf(@qd.thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- MaxApplZone;
- {$ENDC}
-
- if not InitToolsPlus(0, 2, UseColor) then
- ExitToShell;
-
- ApplicationInitialization;
-
- while not ExitTheDemo do {Main Event Loop}
- if PollSystem(Poll) then {If an event is available, process the event…}
-
- case Poll.What of
-
- doMenu:
- ProcessMenuSelection;
-
-
- doChgWindow: {User clicked an inactive window…}
- ActivateWindow(Poll.Window);
-
-
- doRefresh: {Part of window needs to be refreshed}
- begin
- BeginUpdate(WindowPointer(Poll.Window)); {Restrict drawing to area that needs it}
- if Poll.Window = VendorWindow then
- DrawVendorWindow;
- EndUpdate(WindowPointer(Poll.Window)); {End the update for the window (unrestricted drawing)}
- end;
-
-
- doGoAway: {User clicked a window's close box}
- WindowClose(Poll.Window);
-
-
- doButton: { User clicked a button… }
- begin
- CurrentWindow(Poll.Window); {Subsequent action takes place on this window (current grafPort) }
- if Poll.Window = VendorWindow then {Button clicked in 'Vendor' window… }
- case Poll.Button.Num of
- typeAle..typeWater:
- for theButton := typeAle to typeWater do
- SelectButton(theButton, Poll.Button.Num = theButton);
-
- levelHigh..levelLow:
- for theButton := levelHigh to levelLow do
- SelectButton(theButton, Poll.Button.Num = theButton);
-
- OkButton, CancelButton:
- WindowClose(Poll.Window);
- end
-
- else {Button clicked in the 'Debugger' window…}
- case Poll.Button.Num of
- checkSymFile..checkDebugger:
- begin
- SelectButton(Poll.Button.Num, not ButtonIsSelected(Poll.Button.Num));
- if Poll.Button.Num = checkSymFile then
- begin
- { 'Check full path' box is available only when 'Generate SYM File' is on… }
- EnableButton(checkFullPath, ButtonIsSelected(checkSymFile));
- if not ButtonIsEnabled(checkFullPath) then
- SelectButton(checkFullPath, false);
- end
- end;
- OkButton, CancelButton:
- WindowClose(Poll.Window);
- end
- end;
-
-
- doPictButton, doKeyDown, doAutoKey, doClickField, doScrollBar, doListBox, doPopUpMenu, doClick:
- ; {Other core events we're ignoring in this app}
-
- otherwise {All other events are ignored}
- end
- end.